package com.radar.io;

import com.radar.algorithm.MathCommon;
import com.radar.common.ProductType;
import org.meteoinfo.data.GridData;

public class RadarGridData extends GridData {

    public byte[][] radarData;

    public short[][] caclData;

    public double[] getMaxMinValue(ProductType type) {
        double max = java.lang.Double.MIN_VALUE;
        double min = java.lang.Double.MAX_VALUE;
        int vdNum = 0;

        for (int i = 0; i < this.getYNum(); ++i) {
            for (int j = 0; j < this.getXNum(); ++j) {
                double z = MathCommon.Decode(this.radarData[i][j],type);
                if (this.radarData[i][j] != -128) {
                    if (vdNum == 0) {
                        min = z;
                        max = min;
                    } else {
                        if (min > z) {
                            min = z;
                        }

                        if (max < z) {
                            max = z;
                        }
                    }

                    ++vdNum;
                }
            }
        }
        return new double[]{max, min};
    }

    public double[] getCaclMaxMinValue() {
        short max = Short.MIN_VALUE;
        short min = Short.MAX_VALUE;
        int vdNum = 0;

        for (int i = 0; i < this.getYNum(); ++i) {
            for (int j = 0; j < this.getXNum(); ++j) {
                if (this.caclData[i][j] != -128) {
                    if (vdNum == 0) {
                        min = this.caclData[i][j];
                        max = min;
                    } else {
                        if (min > this.caclData[i][j]) {
                            min = this.caclData[i][j];
                        }

                        if (max < this.caclData[i][j]) {
                            max = this.caclData[i][j];
                        }
                    }

                    ++vdNum;
                }
            }
        }
        return new double[]{max / 100.0, min / 100.0};
    }
}
